﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CodeCreator.CoreObj.DbManager
{
    public partial class FrmGetPk : Form
    {
        private List<ObjField> fields = new List<ObjField>();

        public List<ObjField> Fields
        {
            get { return fields; }
            set { fields = value; }
        }

        private string tableName;

        public string TableName
        {
            get { return tableName; }
            set { tableName = value; }
        }
        

        
        public FrmGetPk()
        {
            InitializeComponent();
        }

        private void FrmGetPk_Load(object sender, EventArgs e)
        {
            this.cmbFields.DataSource = fields;
            this.cmbFields.DisplayMember = "dbFieldName";

            this.labTableName.Text = tableName;
      
        }

        private void cmbFields_SelectedIndexChanged(object sender, EventArgs e)
        {
            ObjField f = this.cmbFields.SelectedItem as ObjField;
            if (f != null)
            {
                this.labFieldType.Text = f.DbFieldType;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            ObjField f = this.cmbFields.SelectedItem as ObjField;
            if (f != null)
            {
                f.DbFieldPk = true;

                if (f.DbFieldType.ToUpper() == "NUMBER")
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("主键只能选择NUMBER类型");
                }
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}
